import iconList from '@/icon/iconlist'
export default {
  column: [],
  /**
   * 构建表单元素
   * @param {*} vm 当前vue实例
   * @returns 
   */
  buildColumn(vm) {
    if(!vm) {
      return this.column
    }
    this.column = [
      {
        label:'主键',
        prop:'id',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: true,
        span: 12,
        readonly: false,
        display: false,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '主键不能为空', trigger: "blur" }
        ]},
      {
          label:'父菜单id',
          prop:'parentId',
          type: 'tree',
          dicUrl: '/sys/menu/tree',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: true,
          span: 12,
          readonly: false,
          display: true,
          value: Number('0'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data',
            label: 'name',
            value: 'id'
          },
          rules: [
            { required: false, message: '父菜单id不能为空', trigger: "blur" }
          ]},
      {
        label:'菜单名称',
        prop:'name',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: true, message: '菜单名称不能为空', trigger: "blur" }
        ]},
      {
          label:'菜单类型',
          prop:'menuType',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 12,
          readonly: false,
          display: true,
          value: Number('2'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'sys_menu_menu_type',
            type: 'enum'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: true, message: '菜单类型不能为空', trigger: "blur" }
          ]},
      {
        label:'排序',
        prop:'sort',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '10.00',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '排序不能为空', trigger: "blur" }
        ]},
      {
        label:'权限标识',
        prop:'access',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '权限标识不能为空', trigger: "blur" }
        ]},
      {
        label:'路由地址',
        prop:'path',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '路由地址不能为空', trigger: "blur" }
        ]},
      {
        label:'组件路径',
        prop:'component',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '组件路径不能为空', trigger: "blur" }
        ]},
      {
        label:'图标',
        prop:'icon',
        type: 'icon',
        iconList:  iconList,
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '图标不能为空', trigger: "blur" }
        ]},
      {
          label:'是否显示',
          prop:'isShow',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 12,
          readonly: false,
          display: true,
          value: Number('2'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'yes_no',
            type: 'enum'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: false, message: '是否显示不能为空', trigger: "blur" }
          ]},
      {
          label:'是否缓存',
          prop:'isCache',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 12,
          readonly: false,
          display: true,
          value: Number('1'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'yes_no',
            type: 'enum'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: false, message: '是否缓存不能为空', trigger: "blur" }
          ]},
      {
          label:'是否可用',
          prop:'isEnable',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 12,
          readonly: false,
          display: true,
          value: Number('2'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'yes_no',
            type: 'enum'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: false, message: '是否可用不能为空', trigger: "blur" }
          ]},
      {
        label:'备注',
        prop:'remark',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 12,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '备注不能为空', trigger: "blur" }
        ]},
    ]
    return this.column
  },
  /**
   * 动态构建搜索条件
   * @param {*} vm 当前vue实例
   * @returns 
   */
  buildSearchParam(vm) {
    let res = {}
    vm.option.column.forEach(item=>{
      if(item.search) {
        let key = `m_${item.searchType}_${item.prop}`
        let value = vm.search[item.prop]
        if(value!== undefined) {
          res[key] = value
        }
      }
    })
    return res;
  }
}